<template>
	<view>
		<!-- 头部 -->
		<user-space-head :user="user" :userDesc="userDesc" />
		<!-- 统计 -->
		<view class="space-total">
			<profile-total :userData="userData" />
		</view>
		<view style="height: 20upx; background-color: #F4F4F4;"></view>
		<swiper-tab-head :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" tabItemStyle="width:50%" scrollStyle="border-bottom:none" />

		<template v-if="tabIndex === 0">
			<!-- 用户信息 -->
			<user-space-info :userDesc="userDesc" />
		</template>
		<template v-else>
			<!-- 列表 -->
			<block v-for="(item,index) in list" :key="index">
				<common-list :item="item" />
			</block>
			<!-- 上拉加载-->
			<load-more :loadtext="loadtext" />
		</template>

	</view>
</template>

<script>
	import userSpaceHead from "components/user/user-space-head.vue"
	import profileTotal from "components/profile/profile-total.vue"
	import swiperTabHead from "components/index/swiper-tab-head.vue"
	import userSpaceInfo from "components/user/user-space-info.vue"
	import commonList from "components/common/common-list.vue"
	import loadMore from "components/common/load-more.vue"
	import * as userApi from "network/user.js"
	export default {
		data() {
			return {
				user: {},
				userData: {},
				userDesc: {},
				tabIndex: 0,
				tabBars: [{
						name: "主页",
						id: "zhuye"
					},
					{
						name: "糗事",
						id: "qiushi"
					}
				],
				loadtext: "上拉加载更多",
				list: [{
						user_id: 1,
						userpic: "../../static/image/userpic/12.jpg",
						username: "哈哈哈",
						sex: 1, // 0: 男, 1: 女
						age: 23,
						isfollow: false,
						title: "我是标题",
						titlepic: false,
						video: false,
						share: false,
						site: "深圳 龙岗",
						sharenum: 20,
						commentnum: 30,
						goodnum: 40
					},
					{
						user_id: 1,
						userpic: "../../static/image/userpic/12.jpg",
						username: "哈哈哈",
						sex: 1, // 0: 男, 1: 女
						age: 23,
						isfollow: false,
						title: "我是标题",
						titlepic: false,
						video: false,
						share: false,
						site: "深圳 龙岗",
						sharenum: 20,
						commentnum: 30,
						goodnum: 40
					}
				]
			};
		},
		methods: {
			tabtap(index) {
				this.tabIndex = index
			},
			loadMore() {
				if (this.loadtext !== "上拉加载更多") {
					return
				}
				let obj = {
					userpic: "../../static/image/userpic/12.jpg",
					username: "哈哈哈",
					sex: 1, // 0: 男, 1: 女
					age: 23,
					isfollow: false,
					title: "我是标题",
					titlepic: false,
					video: false,
					share: false,
					site: "深圳 龙岗",
					sharenum: 20,
					commentnum: 30,
					goodnum: 40
				}
				// 修改状态
				this.loadtext = "拼命加载中. . ."
				setTimeout(() => {
					this.list.push(obj)
					this.loadtext = "上拉加载更多"
					// this.attention.loadtext = "人家是有底线的 Ծ ‸ Ծ"
				}, 1000)
			}
		},
		components: {
			userSpaceHead,
			profileTotal,
			swiperTabHead,
			userSpaceInfo,
			commonList,
			loadMore
		},
		async onLoad(e) {
			const res = await userApi.getUserProfile(this.$Route.query.userId)
			this.user = res.data.user
			this.userData = res.data.userData
			this.userDesc = res.data.userDesc
		},
		// 上拉加载
		onReachBottom() {
			this.loadMore()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getData()
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 2000)
		}
	}
</script>

<style lang="scss" scoped>
	.space-total {
		background-color: #FFFFFF;
		position: relative;
		top: -38upx;
		z-index: 20;
		border-radius: 30upx 30upx 0 0;
	}
</style>
